import http from "../utils/http/http";
import axios from 'axios';
//遍历查
const getmeasureInfoData = (data) => {
    return http.get("/measuresInfo/list/", data);
};
//查数据表总记录数
const countmeasureInfoData = (data) => {
    return http.get("/measuresInfo/total/", data);
};

const  findByMeasureCode = (data) => {
    return http.get("/measuresInfo/findByMeasureCode", data);
};

const findByPowerPlantName = (data) => {
    return  http.get("/measuresInfo/findByPowerPlantName", data);
};

const selectMeasureInfoData = async (id) => {
    try{
        const response = await http.get(`/measuresInfo/select/${id}`);
        return response.data;
    } catch (error) {
        console.error('查询单条用户管理数据失败：', error);
        return null;
    }
};


// 添加测点
const addMeasureInfo = async (data) => {
    try {
        const response = await http.post("/measuresInfo/add", data);
        if (response.data.status) {
            return response.data;
        } else {
            throw new Error('测点添加失败');
        }
    } catch (error) {
        console.error('添加测点失败：', error);
        throw error;
    }
};


// 删除测点
const deleteMeasureInfoByCode = (measuresCode) => {
    return http.del(`/measuresInfo/delete/${measuresCode}`);
  };



//更新测点
const updateMeasureInfo = async (measuresCode, data) => {
    try {
        const response = await http.put(`/measuresInfo/update/${measuresCode}`, data);
        if (response.data.status) {
            return response.data;
        } else {
            throw new Error('测点更新失败');
        }
    } catch (error) {
        console.error('更新测点失败：', error);
        throw error;
    }
};

// 导入 Excel 文件的方法
const importExcel = (formData) => {
    return http.post('/measuresInfo/importExcel', formData, {
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    });
};




export default {
    getmeasureInfoData, 
    countmeasureInfoData,
    findByMeasureCode,
    findByPowerPlantName,
    selectMeasureInfoData,
    addMeasureInfo,
    updateMeasureInfo,
    deleteMeasureInfoByCode,
    importExcel,
}